/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using QuocTeViet.DO;
/// <summary>
/// Summary description for cmsSanPhamDAL
/// </summary>
namespace QuocTeViet.DAL
{

    public class cmsSanPhamDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsSanPhamDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsSanPhamDO objcmsSanPhamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@MaSanPham", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.MaSanPham;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TenSanPham", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.TenSanPham;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@eTenSanPham", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.eTenSanPham;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Mota", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.Mota;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@eMoTa", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.eMoTa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MoTaChiTiet", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.MoTaChiTiet;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@eMoTaChiTiet", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.eMoTaChiTiet;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@BaoHanh", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.BaoHanh;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@eBaoHanh", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.eBaoHanh;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LoaiSanPhamID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.LoaiSanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@NhanHieuID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.NhanHieuID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TuKhoa", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.TuKhoa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@eTuKhoa", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.eTuKhoa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@HinhAnh", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.HinhAnh;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DonGia", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.DonGia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@GiamGia", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.GiamGia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SanPhamMoi", SqlDbType.Bit);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamMoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SanPhamBanChay", SqlDbType.Bit);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamBanChay;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DonViID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.DonViID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@XuatXuID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.XuatXuID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsSanPhamDO objcmsSanPhamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@SanPhamID", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MaSanPham", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.MaSanPham;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TenSanPham", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.TenSanPham;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@eTenSanPham", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.eTenSanPham;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Mota", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.Mota;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@eMoTa", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.eMoTa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MoTaChiTiet", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.MoTaChiTiet;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@eMoTaChiTiet", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.eMoTaChiTiet;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@BaoHanh", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.BaoHanh;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@eBaoHanh", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.eBaoHanh;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LoaiSanPhamID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.LoaiSanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@NhanHieuID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.NhanHieuID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TuKhoa", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.TuKhoa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@eTuKhoa", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.eTuKhoa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@HinhAnh", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.HinhAnh;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DonGia", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.DonGia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@GiamGia", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.GiamGia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SanPhamMoi", SqlDbType.Bit);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamMoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SanPhamBanChay", SqlDbType.Bit);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamBanChay;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DonViID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.DonViID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@XuatXuID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.XuatXuID;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsSanPhamDO objcmsSanPhamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@SanPhamID", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }
        public DataTable TimKiem(string tk,int loai,int nhanhieu)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_TimKiem";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@tk", SqlDbType.NVarChar);
            Sqlparam.Value = tk;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@loai", SqlDbType.BigInt);
            Sqlparam.Value = loai;
            Sqlcomm.Parameters.Add(Sqlparam);


            Sqlparam = new SqlParameter("@nh", SqlDbType.BigInt);
            Sqlparam.Value = nhanhieu;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SearchByKey(string tk,int loai,int nhanhieu)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_TimKiem1";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@tk", SqlDbType.NVarChar);
            Sqlparam.Value = tk;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@loai", SqlDbType.BigInt);
            Sqlparam.Value = loai;
            Sqlcomm.Parameters.Add(Sqlparam);


            Sqlparam = new SqlParameter("@nh", SqlDbType.BigInt);
            Sqlparam.Value = nhanhieu;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public cmsSanPhamDO Select(cmsSanPhamDO objcmsSanPhamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@SanPhamID", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["SanPhamID"]))
                    objcmsSanPhamDO.SanPhamID = Convert.ToInt64(dr["SanPhamID"]);
                if (!Convert.IsDBNull(dr["MaSanPham"]))
                    objcmsSanPhamDO.MaSanPham = Convert.ToString(dr["MaSanPham"]);
                if (!Convert.IsDBNull(dr["TenSanPham"]))
                    objcmsSanPhamDO.TenSanPham = Convert.ToString(dr["TenSanPham"]);
                if (!Convert.IsDBNull(dr["eTenSanPham"]))
                    objcmsSanPhamDO.eTenSanPham = Convert.ToString(dr["eTenSanPham"]);
                if (!Convert.IsDBNull(dr["Mota"]))
                    objcmsSanPhamDO.Mota = Convert.ToString(dr["Mota"]);
                if (!Convert.IsDBNull(dr["eMoTa"]))
                    objcmsSanPhamDO.eMoTa = Convert.ToString(dr["eMoTa"]);
                if (!Convert.IsDBNull(dr["MoTaChiTiet"]))
                    objcmsSanPhamDO.MoTaChiTiet = Convert.ToString(dr["MoTaChiTiet"]);
                if (!Convert.IsDBNull(dr["eMoTaChiTiet"]))
                    objcmsSanPhamDO.eMoTaChiTiet = Convert.ToString(dr["eMoTaChiTiet"]);
                if (!Convert.IsDBNull(dr["BaoHanh"]))
                    objcmsSanPhamDO.BaoHanh = Convert.ToString(dr["BaoHanh"]);
                if (!Convert.IsDBNull(dr["eBaoHanh"]))
                    objcmsSanPhamDO.eBaoHanh = Convert.ToString(dr["eBaoHanh"]);
                if (!Convert.IsDBNull(dr["LoaiSanPhamID"]))
                    objcmsSanPhamDO.LoaiSanPhamID = Convert.ToInt32(dr["LoaiSanPhamID"]);
                if (!Convert.IsDBNull(dr["NhanHieuID"]))
                    objcmsSanPhamDO.NhanHieuID = Convert.ToInt32(dr["NhanHieuID"]);
                if (!Convert.IsDBNull(dr["TuKhoa"]))
                    objcmsSanPhamDO.TuKhoa = Convert.ToString(dr["TuKhoa"]);
                if (!Convert.IsDBNull(dr["eTuKhoa"]))
                    objcmsSanPhamDO.eTuKhoa = Convert.ToString(dr["eTuKhoa"]);
                if (!Convert.IsDBNull(dr["HinhAnh"]))
                    objcmsSanPhamDO.HinhAnh = Convert.ToString(dr["HinhAnh"]);
                if (!Convert.IsDBNull(dr["DonGia"]))
                    objcmsSanPhamDO.DonGia = Convert.ToInt64(dr["DonGia"]);
                if (!Convert.IsDBNull(dr["GiamGia"]))
                    objcmsSanPhamDO.GiamGia = Convert.ToInt64(dr["GiamGia"]);
                if (!Convert.IsDBNull(dr["SanPhamMoi"]))
                    objcmsSanPhamDO.SanPhamMoi = Convert.ToBoolean(dr["SanPhamMoi"]);
                if (!Convert.IsDBNull(dr["SanPhamBanChay"]))
                    objcmsSanPhamDO.SanPhamBanChay = Convert.ToBoolean(dr["SanPhamBanChay"]);
                if (!Convert.IsDBNull(dr["DonViID"]))
                    objcmsSanPhamDO.DonViID = Convert.ToInt32(dr["DonViID"]);
                if (!Convert.IsDBNull(dr["XuatXuID"]))
                    objcmsSanPhamDO.XuatXuID = Convert.ToInt32(dr["XuatXuID"]);

            }
            return objcmsSanPhamDO;
        }
        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsSanPhamDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsSanPhamDO objcmsSanPhamDO = new cmsSanPhamDO();
                    if (!Convert.IsDBNull(dr["SanPhamID"]))
                        objcmsSanPhamDO.SanPhamID = Convert.ToInt64(dr["SanPhamID"]);
                    if (!Convert.IsDBNull(dr["MaSanPham"]))
                        objcmsSanPhamDO.MaSanPham = Convert.ToString(dr["MaSanPham"]);
                    if (!Convert.IsDBNull(dr["TenSanPham"]))
                        objcmsSanPhamDO.TenSanPham = Convert.ToString(dr["TenSanPham"]);
                    if (!Convert.IsDBNull(dr["eTenSanPham"]))
                        objcmsSanPhamDO.eTenSanPham = Convert.ToString(dr["eTenSanPham"]);
                    if (!Convert.IsDBNull(dr["Mota"]))
                        objcmsSanPhamDO.Mota = Convert.ToString(dr["Mota"]);
                    if (!Convert.IsDBNull(dr["eMoTa"]))
                        objcmsSanPhamDO.eMoTa = Convert.ToString(dr["eMoTa"]);
                    if (!Convert.IsDBNull(dr["MoTaChiTiet"]))
                        objcmsSanPhamDO.MoTaChiTiet = Convert.ToString(dr["MoTaChiTiet"]);
                    if (!Convert.IsDBNull(dr["eMoTaChiTiet"]))
                        objcmsSanPhamDO.eMoTaChiTiet = Convert.ToString(dr["eMoTaChiTiet"]);
                    if (!Convert.IsDBNull(dr["BaoHanh"]))
                        objcmsSanPhamDO.BaoHanh = Convert.ToString(dr["BaoHanh"]);
                    if (!Convert.IsDBNull(dr["eBaoHanh"]))
                        objcmsSanPhamDO.eBaoHanh = Convert.ToString(dr["eBaoHanh"]);
                    if (!Convert.IsDBNull(dr["LoaiSanPhamID"]))
                        objcmsSanPhamDO.LoaiSanPhamID = Convert.ToInt32(dr["LoaiSanPhamID"]);
                    if (!Convert.IsDBNull(dr["NhanHieuID"]))
                        objcmsSanPhamDO.NhanHieuID = Convert.ToInt32(dr["NhanHieuID"]);
                    if (!Convert.IsDBNull(dr["TuKhoa"]))
                        objcmsSanPhamDO.TuKhoa = Convert.ToString(dr["TuKhoa"]);
                    if (!Convert.IsDBNull(dr["eTuKhoa"]))
                        objcmsSanPhamDO.eTuKhoa = Convert.ToString(dr["eTuKhoa"]);
                    if (!Convert.IsDBNull(dr["HinhAnh"]))
                        objcmsSanPhamDO.HinhAnh = Convert.ToString(dr["HinhAnh"]);
                    if (!Convert.IsDBNull(dr["DonGia"]))
                        objcmsSanPhamDO.DonGia = Convert.ToInt64(dr["DonGia"]);
                    if (!Convert.IsDBNull(dr["GiamGia"]))
                        objcmsSanPhamDO.GiamGia = Convert.ToInt64(dr["GiamGia"]);
                    if (!Convert.IsDBNull(dr["SanPhamMoi"]))
                        objcmsSanPhamDO.SanPhamMoi = Convert.ToBoolean(dr["SanPhamMoi"]);
                    if (!Convert.IsDBNull(dr["SanPhamBanChay"]))
                        objcmsSanPhamDO.SanPhamBanChay = Convert.ToBoolean(dr["SanPhamBanChay"]);
                    if (!Convert.IsDBNull(dr["DonViID"]))
                        objcmsSanPhamDO.DonViID = Convert.ToInt32(dr["DonViID"]);
                    if (!Convert.IsDBNull(dr["XuatXuID"]))
                        objcmsSanPhamDO.XuatXuID = Convert.ToInt32(dr["XuatXuID"]);
                    arrcmsSanPhamDO.Add(objcmsSanPhamDO);
                }
            }
            return arrcmsSanPhamDO;
        }
        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectMoi(int id)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_GetTopMoi";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@id", SqlDbType.Int);
            Sqlparam.Value = id;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectNoiBat(int id)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_GetTopNoiBat";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@id", SqlDbType.Int);
            Sqlparam.Value = id;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
            }
            return dt;
        }
        public DataTable SelectByLoaiAnhNhanHieu(int LoaiSanPhamID, int nhanhieu)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_SelectByLoaiAnhNhanHieu";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@loai", SqlDbType.Int);
            Sqlparam.Value = LoaiSanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@nhanhieu", SqlDbType.Int);
            Sqlparam.Value = nhanhieu;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);



            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable SelectByLoaiSanPhamAnhNhanHieu(int nhanHieuID, int loaiSanPhamID)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_SelectByNhanHieuAndLoaiSanPham";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@NhanHieuID", SqlDbType.Int);
            Sqlparam.Value = nhanHieuID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LoaiSanPhamID", SqlDbType.Int);
            Sqlparam.Value = loaiSanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);



            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectCungLoai(int id)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_getCungLoai";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@id", SqlDbType.Int);
            Sqlparam.Value = id;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);



            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public void UpdateAll(int stt, int[] spid, long[] dongia)
        {
            SqlCommand SqlComm = new SqlCommand();
            SqlComm.CommandType = CommandType.Text;
            string s = "";
            for (int i = 0; i < stt; i++)
            {
                s += "Update cmsSanPham set DonGia= " + dongia[i] + " where SanPhamID=" + spid[i] + " ";
            }
            SqlComm.CommandText = s;

            base.ExecuteNoneQuery(SqlComm);
        }
        public DataTable SelectByTag(string tag,int i)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_GetByTag";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@tag", SqlDbType.NVarChar);
            Sqlparam.Value = tag;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@i", SqlDbType.Int);
            Sqlparam.Value = i;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable cmsSanPham_SelectByPhanLoai(int PhanLoai)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "cmsSanPham_SelectByPhanLoai";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@PhanLoai", SqlDbType.Int);
            Sqlparam.Value = PhanLoai;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);



            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        #endregion

    }

}
